function Rocket(){
	this.gameEngine = null;	
	this.parent = new GameObject();
		
	this.maxFuel = 200;
	this.currentFuel = 200;
	
	this.imageOn = new Image();
	this.imageOff = new Image();
		
	this.thrustOn = false;
	this.shooting = false;
	
	this.maxVelocity = 10;
	
	this.maxShieldPower = 200;
	this.currentShieldPower = this.maxShieldPower;
	
	this.updatePosition = function(){
		var ax = 0;
		var ay = 0;
		
		if(keydown.space && this.currentFuel>0){
			this.currentFuel=Math.max(0,this.currentFuel-1);
			ax = this.parent.linearAcceleration*Math.cos(this.parent.angle);
			ay = this.parent.linearAcceleration*Math.sin(this.parent.angle);
			this.thrustOn = true;			
			// var velocityAngle = -Math.atan2(this.xVelocity,this.yVelocity);			
			// var diffAngle = this.angle - velocityAngle;
			// var breakAccelerationPart = Math.abs(Math.sin(diffAngle/2));
																
		}
		else{
			this.thrustOn = false;
			if(!keydown.space){
				this.currentFuel=Math.min(this.maxFuel,this.currentFuel+1);
			}
		}
		
		if(this.parent.xVelocity>0){
			if(ax>0){
				ax = Math.max(0,ax - this.parent.breakAcceleration);
			}				
			else if(ax<=0){
				ax -= this.parent.breakAcceleration;
			}										
		}
		else if(this.parent.xVelocity<0){
			if(ax>=0){
				ax +=this.parent.breakAcceleration;
			}				
			else if(ax<0){
				ax = Math.min(0,ax + this.parent.breakAcceleration);
			}						
		}
		
		if(this.parent.yVelocity>0){
			if(ay>0){
				ay = Math.max(0,ay - this.parent.breakAcceleration);
			}				
			else if(ay<=0){
				ay -= this.parent.breakAcceleration;
			}										
		}
		else if(this.parent.yVelocity<0){
			if(ay>=0){
				ay += this.parent.breakAcceleration;
			}				
			else if(ay<0){
				ay = Math.min(0,ay + this.parent.breakAcceleration);
			}					
		}				
		
		this.parent.x+=this.parent.xVelocity + ax/2;
		this.parent.y+=this.parent.yVelocity + ay/2;
		
		this.parent.xVelocity = Math.min(this.parent.xVelocity+ax,this.maxVelocity);
		this.parent.yVelocity = Math.min(this.parent.yVelocity+ay,this.maxVelocity);		
	}
	this.updateRotation = function(){
		var targetAngle = Math.atan2(this.parent.targetY-this.parent.y,this.parent.targetX-this.parent.x);
		var targetAngle2 = targetAngle-2*Math.PI;
		var targetAngle3 = targetAngle+2*Math.PI;
		
		if(Math.abs(this.parent.angle - targetAngle) > Math.abs(this.parent.angle - targetAngle2)){
			this.parent.angle+=2*Math.PI;
		}
		if(Math.abs(this.parent.angle - targetAngle) > Math.abs(this.parent.angle - targetAngle3)){
			this.parent.angle-=2*Math.PI;
		}
		
		if(Math.abs(this.parent.angle - targetAngle)<this.parent.rotationAcceleration){
			this.parent.angle = targetAngle;	
		}
		else if(this.parent.angle>targetAngle){
			this.parent.angle-=this.parent.rotationAcceleration;
		}
		else if(this.parent.angle<targetAngle){
			this.parent.angle+=this.parent.rotationAcceleration;
		}			
	}
	this.shootGravityMissile = function(){	
		var missile = new GravityMissile();
		missile.parent.angle = this.parent.angle;
		missile.parent.x = this.parent.x + (this.parent.collisionRadius)*Math.cos(this.parent.angle);
		missile.parent.y = this.parent.y + (this.parent.collisionRadius)*Math.sin(this.parent.angle);		
		missile.init();
		this.gameEngine.addObject(missile);
		
	}	
	this.update = function(){		
		this.updatePosition();											
		this.updateRotation();
		if(keydown.z && !this.shooting){
			this.shooting = true;
			this.shootGravityMissile();
		}
		if(!keydown.z){
			this.shooting = false;
		}
	}
	this.draw = function(ctx){			
		ctx.translate(this.parent.x,this.parent.y);
		ctx.fillStyle = "red";
		var len = (this.parent.collisionRadius*2*this.currentShieldPower)/this.maxShieldPower;
		ctx.fillRect(-this.parent.collisionRadius,-this.parent.collisionRadius-10,len,5);
		ctx.strokeRect(-this.parent.collisionRadius,-this.parent.collisionRadius-10,this.parent.collisionRadius*2,5);
		ctx.rotate(this.parent.angle);	
				
				
		if(this.thrustOn){			
			ctx.drawImage(this.gameEngine.imageManager.rocketOn,
			-55,
			-this.parent.collisionRadius
			);			
		}
		else{
			ctx.drawImage(this.gameEngine.imageManager.rocketOff,
			-55,
			-this.parent.collisionRadius);			
		}
// 		
		/*ctx.beginPath();
		ctx.arc(0,0,this.parent.collisionRadius,0,2*Math.PI,true);
		ctx.strokeStyle="gray";
		//ctx.strokeRect(-10,-20,30,50);
		ctx.stroke();
		ctx.closePath();						*/
	}
		
	this.parent.objectCollisionCallback = function(that,obj1){
		that.currentShieldPower = Math.max(0,that.currentShieldPower-obj1.parent.collisionDamage);
	}
}